package com.example.apigeneratorplusissues.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.apigeneratorplusissues.model.*;
import com.example.apigeneratorplusissues.model.response.JsonSerializerResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.example.apigeneratorplusissues.constant.Constants.COMMON_PATH;

/**
 * @author limaoxu 2021/5/31 16:04
 */
@RestController
@RequestMapping(path = "/json/" + COMMON_PATH + "/serializer")
public class TestController {

    private static final String CONTENT_TYPE_JSON = "application/*";

    private static final String ID = "id_15";

    @GetMapping("/index2/" + ID)
    public ResponseWrap<JsonSerializerResponse> index(){
        JsonSerializerResponse response = new JsonSerializerResponse();
        response.setImageUrl("/th?id=OSK.wT-MbJ6EIE2AmjALQlN9XjAeDCj0d0I83bb3giUGQ5I&r=0&o=6&pid=13.1");
        return ResponseWrap.<JsonSerializerResponse>builder().data(response).build();
    }

    @RequestMapping(value = "/satoken")
    @ResponseBody
    public SaResult test() throws Exception {
        StpUtil.login(1);
        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        tokenInfo.getTokenValue();
        return SaResult.data(tokenInfo);
    }

    @RequestMapping(value = "/xxx")
    @ResponseBody
    public ResponseEntity<BasicDataType> test(HttpServletRequest request, HttpServletResponse response, String name) throws Exception {
        BasicDataType body = new BasicDataType();
        return ResponseEntity.ok(body);
    }

    /**
     * application
     * @param projectId
     * @param name
     * @param query
     * @return
     */
    @PostMapping("/{projectId}/application")
    public ResponseWrap<PageInfoWrap<ApplicationVO>> listApplicationInProject(@PathVariable Long projectId,
                                                                              String name,
                                                                              PageQueryRequest pageQueryRequest,
                                                                              @RequestBody PageQueryRequest query) {
        return null;
    }


    @GetMapping("/{projectId}/application")
    public ResponseWrap<PageInfoWrap<ApplicationVO>> getlistApplicationInProject(@PathVariable Long projectId,
                                                                                 String name,
                                                                                 PageQueryRequest query,
                                                                                 @RequestAttribute String requestAttribute) {
        return null;
    }

    @RequestMapping(value = "/xx111x", produces = CONTENT_TYPE_JSON)
    @ResponseBody
    public String test1(HttpServletRequest request, HttpServletResponse response,
                        MultipartFile file,
                        String name) throws Exception {
        return "success";
    }

    @PostMapping("/test2")
    public void test2(String name, PageQueryRequest request){

    }

}
